package com.example.hhh.service.impl;

import com.example.hhh.model.Business;
import com.example.hhh.repository.BusinessRepository;
import com.example.hhh.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    private final BusinessRepository businessRepository;

    @Autowired
    public BusinessServiceImpl(BusinessRepository businessRepository) {
        this.businessRepository = businessRepository;
    }

    @Override
    public Business createBusiness(Business business) {
        return businessRepository.save(business);
    }

    @Override
    public Business getBusinessById(Integer id) {
        return businessRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("Business not found with id: " + id));
    }

    @Override
    public Page<Business> getAllBusinesses(Pageable pageable) {
        return businessRepository.findAll(pageable);
    }

    @Override
    public List<Business> findByBusinessType(String type) {
        return businessRepository.findByBusinessType(type);
    }

    @Override
    public List<Business> findBusinessByCostRange(Double min, Double max) {
        return businessRepository.findBusinessByCostRange(min, max);
    }
}